<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button style="background-color: rgb(233, 175, 0);border: none;" @click="createStandardItemByExamPaper()"
                type="primary" icon="copy">一键生成规则
      </a-button>
      <a-popconfirm title="此操作将删除现有数据后重新生成相关数据,确定删除?" @confirm="() => resetStandardItemByExamPaper()">
        <a-button style="background-color: rgb(255, 0, 0);border: none;"
                  type="primary" icon="copy">删除重设
        </a-button>
      </a-popconfirm>
      <!-- 高级查询区域 -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
      <template>
        <span style="float:right;">
          <a @click="searchQuery()"><a-icon type="sync" />刷新</a>
          <a-divider type="vertical" />
          <a-button v-print="'#datatable'" ghost type="primary">打印</a-button>
        </span>
      </template>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="tableData"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDeleteItemById(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <standard-item-for-points-rules-modal ref="modalForm" @ok="diyFlashTable"></standard-item-for-points-rules-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { mixinDevice } from '@/utils/mixin'
import { deleteAction, getAction } from '@api/manage'
import StandardItemForPointsRulesModal from './modules/StandardItemForPointsRulesModal'

export default {
  name: 'StandardItemForPointsRules',
  title: '计分规则',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    StandardItemForPointsRulesModal
  },
  data() {
    return {
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '科目',
          align: 'center',
          dataIndex: 'subjectId_dictText'
        },
        {
          title: '试卷',
          align: 'center',
          dataIndex: 'exaPapProItemCode_dictText'
        },

        {
          title: '简称',
          align: 'center',
          dataIndex: 'standItemAliasname'
        },
        {
          title: '权重系数',
          align: 'center',
          dataIndex: 'standItemWeightCoefficient'
        },
        {
          title: '项目序号',
          align: 'center',
          sorter: true,
          dataIndex: 'standItemOrder'
        },
        {
          title: '特殊限制',
          align: 'center',
          dataIndex: 'standItSpecialRestrictions_dictText'
        },
        {
          title: '是否启用',
          align: 'center',
          dataIndex: 'izOpen_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/achachievestandarditem/achAchieveStandardItem/list',
        delete: '/achachievestandarditem/achAchieveStandardItem/delete',
        deleteBatch: '/achachievestandarditem/achAchieveStandardItem/deleteBatch',
        exportXlsUrl: '/achachievestandarditem/achAchieveStandardItem/exportXls',
        importExcelUrl: 'achachievestandarditem/achAchieveStandardItem/importExcel'
      },
      tableData: [],
      examId: '',
      dictOptions: {},
      superFieldList: []
    }
  },
  methods: {
    loadData(arg, examId) {
      if (arg === 1) {
        this.ipagination.current = 1
      }
      let searchUrl = '/achachievestandarditem/achAchieveStandardItem/queryAchievementsItemByRelObjIdType'
      let params = {
        relObjId: examId,
        achievementStandardPurpose: '93',
        pageNo: this.ipagination.current,
        pageSize: this.ipagination.pageSize
      }
      console.log('执行了刷新' + this.examId)
      if (examId) {
        this.examId = examId
        getAction(searchUrl, params).then(res => {
          if (res.success) {
            this.tableData = []
            this.tableData = res.result.records
            this.ipagination.total = res.result.total
          } else {
            this.$message.error(res.message)
          }
        })
      }
    },
    getOrderMain(examId) {
      this.examId = examId
      this.loadData(1, examId)
    },
    //一键生成规则
    createStandardItemByExamPaper() {
      let params = {}
      if (this.examId != '') {
        params.examId = this.examId
      }
      getAction('/achachievestandarditem/achAchieveStandardItem/createStandardItemByExamPaper', params).then(res => {
        if (res.success) {
          this.$message.success('生成成功')
          this.loadData(1, this.examId)
        } else {
          this.$message.error(res.message)
        }
      })
    },
    resetStandardItemByExamPaper() {
      let params = {}
      if (this.examId != '') {
        params.examId = this.examId
      }
      getAction('/achachievestandarditem/achAchieveStandardItem/resetStandardItemByExamPaper', params).then(res => {
        if (res.success) {
          this.$message.success('重置成功')
          this.loadData(1, this.examId)
        } else {
          this.$message.error(res.message)
        }
      })
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'achievementStandardId', text: '所属上级标准id', dictCode: '' })
      fieldList.push({ type: 'string', value: 'subjectId', text: '科目id', dictCode: '' })
      fieldList.push({ type: 'string', value: 'exaPapProItemCode', text: '考试项目code(来源于项目模板或项目分配表）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'standItemCode', text: '标准分项编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'standItemName', text: '标准分项目名称(不及格、及格、良好、优秀等）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'standItemAliasname', text: '标准分项目别名简称', dictCode: '' })
      fieldList.push({ type: 'double', value: 'standItemLowestScore', text: '分数最低分(含)', dictCode: '' })
      fieldList.push({ type: 'double', value: 'standItemHighestScore', text: '分数最高分(不含)', dictCode: '' })
      fieldList.push({ type: 'double', value: 'standItemLowestRate', text: '分数最低分率百分比(含)', dictCode: '' })
      fieldList.push({ type: 'double', value: 'standItemHighestRate', text: '分数最高分率百分比(不含)', dictCode: '' })
      fieldList.push({ type: 'double', value: 'standItemActualScore', text: '标准分项评分实际得分', dictCode: '' })
      fieldList.push({
        type: 'int',
        value: 'standItSpecialRestrictions',
        text: '特殊限制（0无限制，1性别，2年级 3年龄，4预留）',
        dictCode: ''
      })
      fieldList.push({ type: 'double', value: 'sitemSpecRestMinvalue', text: '特殊限制数最小值（含即大于等于或等于）', dictCode: '' })
      fieldList.push({ type: 'double', value: 'sitemSpecRestMaxvalue', text: '特殊限制数最大值（不含或小于）', dictCode: '' })
      fieldList.push({ type: 'int', value: 'standItemOrder', text: '项目序号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'standItemFatherId', text: '上级项目id', dictCode: '' })
      fieldList.push({ type: 'int', value: 'izOpen', text: '是否启用(1是启用，0否停用)', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sysOrgCode', text: '所属部门编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenantId', text: '学校id', dictCode: '' })
      fieldList.push({ type: 'int', value: 'delFlag', text: '0表示未删除,1表示删除', dictCode: '' })
      fieldList.push({ type: 'string', value: 'createBy', text: '创建人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'createTime', text: '创建时间' })
      fieldList.push({ type: 'string', value: 'updateBy', text: '修改人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'updateTime', text: '修改时间' })
      this.superFieldList = fieldList
    },
    diyFlashTable() {
      this.loadData(1, this.examId)
      this.onClearSelected()
    },
    handleDeleteItemById(id) {
      if (!this.url.delete) {
        this.$message.error('请设置url.delete属性!')
        return
      }
      deleteAction(this.url.delete, { id: id }).then((res) => {
        if (res.success) {
          //重新计算分页问题
          this.reCalculatePage(1)
          this.$message.success(res.message)
          this.loadData(1, this.examId)
        } else {
          this.$message.warning(res.message)
        }
      })
    }
  }

}
</script>

<style scoped>

</style>